import time
from selenium.webdriver.common.by import By


def web_wait_response(func, wait=5):
    def inner(*args, **kwargs):
        start_time = time.time()
        while True:
            try:
                rel = func(*args, **kwargs)
                now = time.time()
                if rel or (now-start_time)>wait:
                    break
            except Exception:
                pass 
        return rel
    return inner


@web_wait_response
def web_find_element(bro, xpath):
    return bro.find_element(By.XPATH, xpath) 


@web_wait_response
def web_find_elements(bro, xpath):
    time.sleep(5)
    return bro.find_elements(By.XPATH, xpath)

